package com.ming.DaoImp;

import com.ming.entity.equipment;
import com.ming.util.Database;
import com.ming.Dao.*;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/8/6 0006.
 */
public class equipmentDaoImp extends Database implements equipmentDao {
    public List<equipment> findEquipment(){
        List<equipment> list = new ArrayList<equipment>();
        Connection con = null;
        PreparedStatement stat = null;
        ResultSet rs = null;
        userDao dao = new userDaoImp();
        product_relationDao pr = new product_relationDaoImp();
        try {
            String sql = "select * from equipment ";
            con = Database.getConnection();
            stat = con.prepareStatement(sql);
            rs = stat.executeQuery();
            while(rs.next()){
                equipment eq = new equipment();
                eq.setEid(rs.getInt("eid"));
                eq.setWpid(rs.getInt("wpid"));
                eq.setManufactureTime(rs.getString("manufactureTime"));
                eq.setUserid(rs.getInt("userid"));
                eq.setUlist(dao.findUser(eq.getUserid()));
                eq.setPlist(pr.findProductRelationDaos(eq.getEid()));
                list.add(eq);
            }

        }catch(Exception e){
            e.printStackTrace();
        }finally {
            Database.closeConnection(con,stat,rs);
        }
        return list;
    }
}
